package de.fhk.fst.dvr.recording

import de.fhk.fst.dvr.info.TVStation

class TvShow {

  def dateTimeConverterService

  String name
  TVStation station
  Date startTime
  Date endTime

  static hasMany = [requests : RecordingRequest]

  static constraints = {
    name(blank: false, nullable: false, maxLength: 64, unique: [
      "station",
      "startTime",
      "endTime"
    ])
    station(nullable: false)
    startTime(nullable: false)
    endTime(nullable: false)
  }

  def beforeInsert = {
    startTime = dateTimeConverterService.removeSecondsFromDate(startTime)
    endTime = dateTimeConverterService.removeSecondsFromDate(endTime)
  }

  public String toString() {
    return name + ", " + dateTimeConverterService.convertToDateString(startTime) + " (" + dateTimeConverterService.convertToTimeString(startTime) + " - " + dateTimeConverterService.convertToTimeString(endTime) +")"
  }
}
